package edu.zju.udms.dnavigator.core.utils;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Arrays;

public class ClassUtils {
	
	@SuppressWarnings("rawtypes")
	public static Field[] getAllFields(Class clazz,Class limit){
		ArrayList<Field> list=new ArrayList<>();
		Class cur=clazz;
		while(cur!=null&&!cur.equals(limit)){
			list.addAll(Arrays.asList(cur.getDeclaredFields()));
			cur=cur.getSuperclass();
		}
		return list.toArray(new Field[0]);
	}
	
	public static Field[] getAllFields(Class<?> clazz){
		return getAllFields(clazz,Object.class);
	}
}
